<template>
  <div>
    <div class="table_resource" style="text-align: center">
      <el-table
        :data="showTable"
        border
        style="width: 100%"
        :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
        stripe
      >
        <el-table-column prop="xm" label="姓名" > </el-table-column>
        <el-table-column prop="gh" label="工号" > </el-table-column>
        <el-table-column prop="bm">
          <template slot="header">
            <el-select v-model="selectkey" filterable placeholder="请选择部门">
                 <el-option label="所有部门" value="所有部门">所有部门</el-option>
              <el-option
                v-for="item in departments"
                :key="item.depId"
                :label="item.depName"
                :value="item.depName"
              >
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column fixed="right" width="400">
          <template slot="header">
            <input
              v-model="keywords"
              placeholder="请输入姓名"
              class="el-input__inner"
            />
          </template>
          <template slot-scope="scope">
            <el-button size="mini"  type="primary" @click="handleEdit(scope.$index, scope.row)" v-if="teacherinfo.xm!=scope.row.xm">重置账号</el-button>
			<el-button size="mini"  type="primary" @click="handleEdit(scope.$index, scope.row)" v-else :disabled="true">重置账号</el-button>
			<!-- <button :disabled="true">1</button> -->
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="resource-page">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[5, 10, 15]"
        :page-size="pagesize"
        :pager-count="5"
        layout=" prev, pager, next,sizes, jumper"
        :total="filterDataShow.length"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
	  teacherinfo:{},
      selectkey: "所有部门", //下拉菜单关键字
      keywords: "", // 搜索的关键字
      filterDataShow: [], //储存符合条件的数据
      departments: [],
      tableData: [],
      pagesize: 15,
      currentPage: 1,
    };
  },
  mounted() {
    this.getDepartmentAxios();
    this.getDataAxios();
	this.teacherinfo = this.$store.state.info;
	// console.log(this.teacherinfo)
  },
  methods: {
    //获取部门数据
    getDepartmentAxios() {
      let that = this;
      this.$api.department
        .getSchoolDepartments()
        .then(function (response) {
          console.log(response);
          that.departments = response.data.data.departments;
          that.searchResource();
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    //获取批次数据
    getDataAxios() {
      let that = this;
      this.$api.teacher
        .getAllTeacherInfo({})
        .then(function (response) {
          that.tableData = response.data.data
          that.searchResource();
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    //查询
    searchResource() {
      this.currentPage = 1; //将当前页设置为1，确保每次都是从第一页开始搜
      let filterKeywords = this.keywords.trim();
      let filerReasource = this.tableData.filter((item) => {
		 
        //过滤全部数据
        if (
          item.xm.includes(filterKeywords) &&
          (item.bm.includes(this.selectkey)||this.selectkey=="所有部门")
        ) {
          return item;
        }
      });
      this.filterDataShow = filerReasource; //将符合条件的内容赋给filterDataShow
    },
    onSubmit() {},
    handleSizeChange(psize) {
      this.pagesize = psize;
    },
    handleCurrentChange(currentPage) {
      this.currentPage = currentPage;
    },
    handleEdit(index, row) {
		// console.log(row.gh)
		
      // this.$router.push({ path: "/batchSetting" });
	  this.$confirm('是否要重置该教师账号?', '提示', {
	            confirmButtonText: '确定',
	            cancelButtonText: '取消',
	            type: 'warning',
	            center: true
	          }).then(() => {
				 this.$api.teacher.resetTeacher({
				  	gh:row.gh
				  }).then((response)=>{
					  console.log(response)
				  })
	            this.$message({
	              type: 'success',
	              message: '重置成功!'
	            });
				
	          }).catch(() => {
	            this.$message({
	              type: 'info',
	              message: '已取消重置'
	            });
	          });
	  
    },
    handleDelete(index, row) {
      console.log(row);
    },
  },
  watch: {
    //监听搜索框内容，当搜索框内容发生变化时调用searchResource方法
    keywords() {
      this.searchResource();
    },
    selectkey() {
      this.searchResource();
    },
  },
  computed: {
    //showTable计算属性通过slice方法计算表格当前应显示的数据
    showTable() {
      return this.filterDataShow.slice(
        (this.currentPage - 1) * this.pagesize,
        this.currentPage * this.pagesize
      );
    },
  },
};
</script>
<style scoped>
#find {
  width: 400px;
  margin-bottom: 30px;
}
</style>